/*******************************************************************************
 *  Test Data Factory
 *  copyright (c) 2011 breakingpoint.com Co.,Ltd. 
 *  Apex Class		: DataFactoryTest.cls 
 *  Summary			: copy from SmartFactory
 *  Refer Object    : 
 *  Author          :        
 *  CreatedDate    	: unknow
 *  Change Log     	: 
 ******************************************************************************/	
@isTest
private class DataFactoryTest {
	static testMethod void createsSingleObjectWithSingleRequiredStringField() {
		Account account = (Account)DataFactory.createSObject('Account');
		insert account;
		System.assert(account.Id != null);
		System.assert(account.Name != null);
	}
	
	static testMethod void createsObjectWithCascadeSetsLookupField() {
		Contact contact = (Contact)DataFactory.createSObject('Contact', true, true);
		insert contact;
		System.assert(contact.Id != null);
		System.assert(contact.AccountId != null);
	}
	
	static testMethod void createsObjectWithoutCascadeDoesNotSetLookupField() {
		Integer num = [select count() from Account];
		Contact contact = (Contact)DataFactory.createSObject('Contact', false, true);
		insert contact;
		System.assert(num > 0 ? contact.AccountId !=null : contact.AccountId == null);
	}
	
	static testMethod void createObjectWithUnsupportedTypeThrowsException() {
		try {
			DataFactory.createSObject('Unsupported');
			System.assert(false);
		} catch (UnsupportedObjectTypeException ex) {
			System.assert(true);
		}
	}
	
	static testMethod void createNewSObjectNotQueryFromSFDC(){
		Contact con;
		try{
			con = (Contact)DataFactory.createSObject('Contact',true, false);
			insert con;
			System.assert(con != null);
		}catch(Exception e){
			System.assert(con == null);
		}
	}

}